package com.example.demo.day.config.learn.test1.service.impl;

import com.example.demo.day.config.learn.test1.User;
import com.example.demo.day.config.learn.test1.repository.UserRepository;
import com.example.demo.day.config.learn.test1.service.HelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class HelloServiceImpl implements HelloService {

    Logger logger = LoggerFactory.getLogger(HelloServiceImpl.class);

    @Resource
    private UserRepository userRepository;

    @Override
    public String ss() {
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

        User user = (User) context.getBean("user");
        logger.info("ss{}",user);
        return user.getUsername();
    }

    @Override
    public Object findAllUsers() {
        return userRepository.findAll();
    }
}
